package com.yuexun.beilunpatient.ui.inspect.presenter.impl;

import com.yuexun.beilunpatient.base.BaseEntity;
import com.yuexun.beilunpatient.ui.inspect.bean.CheckDtlRowSet;
import com.yuexun.beilunpatient.ui.inspect.model.IInspectDetailModel;
import com.yuexun.beilunpatient.ui.inspect.presenter.IInspectDetailPresenter;
import com.yuexun.beilunpatient.ui.inspect.ui.view.IInspectDetailView;

import org.kymjs.kjframe.ui.ViewInject;

import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by chenss on 2018/10/11.
 */
public class InspectDetailPresenter implements IInspectDetailPresenter {

    private IInspectDetailModel model;
    private IInspectDetailView view;

    public InspectDetailPresenter(IInspectDetailView view, IInspectDetailModel model) {
        this.view = view;
        this.model = model;
    }

    @Override
    public void inquireCheckDetail(Map<String, String> praise) {
        model.inquireCheckDetail(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<BaseEntity<CheckDtlRowSet>>() {
                    @Override
                    public void onCompleted() {
                        view.dismiss();
                    }

                    @Override
                    public void onError(Throwable e) {
                        ViewInject.toast("请检查网络状态");
                    }

                    @Override
                    public void onNext(BaseEntity<CheckDtlRowSet> bean) {
                        view.showInspectDetail(bean.getDatas());
                    }
                });
    }
}
